package edu.pw.treegrid.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.user.client.ui.RootPanel;

import edu.pw.treegrid.client.report.view.ReportPanel;


public class XalanReports implements EntryPoint {

	public void onModuleLoad() {
		NodeList<Element> divs = Document.get().getElementsByTagName("div");
        for(int i=0;i<divs.getLength();++i) {
            Element e = divs.getItem(i);
            if(e.getClassName().equals("xalan_report")) {
                String reportId = e.getId();
                String hierarchyId = getHierarchyId(e);
                RootPanel.get(reportId).add(new ReportPanel(reportId, hierarchyId));
            }
        }
	}
	
	private String getHierarchyId(Element e) {
		NodeList<Element> childs = e.getElementsByTagName("div");
        for(int j=0;j<childs.getLength();++j) {
        	Element c = childs.getItem(j);
        	if(c.getClassName().equals("hierarchy")) {
        		return c.getId();
        	}
        }
        return null;
	}
}
